<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <div id="app"></div>
    <!-- 1.引入依赖 -->
    <script src="../../react/react.development.js"></script>
    <script src="../../react/react-dom.development.js"></script>
    <script src="../../react/babel.min.js"></script>
    <!-- 2.开始开发 -->
    <script type="text/babel">
      class App extends React.Component {
        constructor() {
          super()

          // 定义数据
          this.state = {
            message: 'hello world'
          }
        }

        render() {
          return (
            <div>
              <h2>{this.state.message}</h2>
              <button onClick={this.btnClick.bind(this)}>改变文本</button>
            </div>
          )
        }

        btnClick() {
          // 通过setState来修改state中的状态
          // 当前的回调函数是React来调用的,绑定的this是undefined
          // 需要通过 bind 显示绑定 this
          this.setState({
            message: 'hello react'
          })
        }
      }
      ReactDOM.render(<App />, document.getElementById('app'))
    </script>
  </body>
</html>
